package com.wedimob.slideshare;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import com.wedimob.slideshare.source.Source;
import com.wedimob.slideshare.task.Monitor;
import com.wedimob.slideshare.task.io.disk.PathHelper;

public class Main {

	private static class ProgressBar implements Observer {

		@Override
		public void update(Observable obj, Object msg) {
			if (obj instanceof Monitor) {
				System.out.println("Progress : "
						+ Math.round(10000.0 * (Double) msg) / 100 + " %");
			}
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try {
			System.out.println("start ...");
			long begin = System.currentTimeMillis();

			List<SearchCriteria> criterias = new ArrayList<SearchCriteria>() {{
				add(new SearchCriteria(
						"Startup",
						SortBy.RELEVANCE, 30));
				add(new SearchCriteria(
						"Amazon ec2",
						SortBy.RELEVANCE, 30));
				add(new SearchCriteria(
						"big data",
						SortBy.RELEVANCE, 30));
				add(new SearchCriteria(
						"what every should know",
						SortBy.RELEVANCE, 30));
				add(new SearchCriteria(
						"android best practice",
						SortBy.RELEVANCE, 30));
				add(new SearchCriteria(
						"islamic finance",
						SortBy.RELEVANCE, 30));
				add(new SearchCriteria(
						"debuter une activite seul",
						SortBy.RELEVANCE, 30));
				add(new SearchCriteria(
						"android big data",
						SortBy.RELEVANCE, 30));
				add(new SearchCriteria(
						"Architectural Patterns and Software Architectures: Client-Server, Multi-Tier, MVC, MVP, MVVM, IoC, DI, SOA, Cloud Computing",
						SortBy.RELEVANCE, 30));
			}};

			for (SearchCriteria criteria : criterias)
				Search.searchDocuments(criteria, WriteType.ONDISK,
						new ProgressBar());

			System.out.println("done in "
					+ (System.currentTimeMillis() - begin) / 1000 + " sec");
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		} finally {
			try {
				RuntimeConfig.getInstance().getWriter()
						.delete(PathHelper.buildTmpPath());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	}

}
